package main.Q1301_1400;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Q1351_1360 {
    public static void main(String[] args) {
        System.out.println("Question1351：统计有序矩阵中的负数");
        System.out.println("Question1352：");
        System.out.println("Question1353：");
        System.out.println("Question1354：");
        System.out.println("Question1355：");
        System.out.println("Question1356：根据数字二进制下1的数目排序");
        System.out.println("Question1357：");
        System.out.println("Question1358：");
        System.out.println("Question1359：");
        System.out.println("Question1360：");
    }
}

class Question1351{
    public int process(int[] arr){
        int count=0,left=0,right= arr.length-1;
        if (arr[right]>=0) count=0;
        else if (arr[left]<0) count=right+1;
        else {
            while (left<right){
                int mid=left+(right-left)/2;
                if (arr[mid]>=0) left=mid+1;
                else if (arr[mid]<0) right=mid-1;
            }
            if (arr[left]>=0) count=arr.length-1-left;
            else count=arr.length-left;
        }
        return count;
    }
    public int countNegatives(int[][] grid) {
        int count=0;
        for (int[] arr:grid){
            count+=process(arr);
        }
        return count;
    }
}

class Question1356{
    public int[] sortByBits(int[] arr) {
        List<Integer> list=new ArrayList<>();
        for (int num:arr) list.add(num);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                int count1=Integer.bitCount(o1),count2=Integer.bitCount(o2);
                if (count1!=count2) return count1-count2;
                else return o1-o2;
            }
        });
        for (int i=0;i<list.size();i++){
            arr[i]=list.get(i);
        }
        return arr;
    }
}